package com.ruoyi.StarStudio.Live.controller;

import com.alibaba.fastjson.JSONObject;
import com.arronlong.httpclientutil.exception.HttpProcessException;
import com.ruoyi.StarStudio.Live.common.CONST;
import com.ruoyi.StarStudio.Live.common.ResultMap;
import com.ruoyi.StarStudio.Live.servcie.OpenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @projectName: imouplaySvr-main
 * @package: com.imou.live.controller
 * @className: MovePTZController
 * @author: Hyt
 * @description: TODO
 * @date: 2022/5/19 14:28
 * @version: 1.0
 */

@RestController
public class MovePTZController {

    private static Logger logger = LoggerFactory.getLogger(MovePTZController.class);

    @Autowired
    public OpenService openService;

    /**
     * 控制云台移动
     *
     * @return
     */
    @PostMapping("/controlMovePTZ")
    public ResultMap controlMovePTZ(@RequestBody JSONObject jsonParam) throws HttpProcessException {
        ResultMap resultMap = new ResultMap(CONST.RESULT_CG.OK_CODE, CONST.RESULT_CG.OK_MSG);

        if (jsonParam.get("deviceId") == null||jsonParam.get("channelId") == null || jsonParam.get("operation") == null||jsonParam.get("duration") == null) {
            resultMap.setCode(CONST.RESULT_CG.PARAM_NULL_CODE);
            resultMap.setMsg(CONST.RESULT_CG.PARAM_NULL_MSG);
            logger.info("请求参数为空:" + jsonParam.toString());
            return resultMap;
        }

        openService.updateAccessToken(CONST.OPEN_SYSTEM.APPID,CONST.OPEN_SYSTEM.SECRET);
        String accessToken = CONST.OPEN_SYSTEM.accessToken;
        String channelId = jsonParam.get("channelId").toString();
        String operation = jsonParam.get("operation").toString();
        String deviceId = jsonParam.get("deviceId").toString();
        String duration = jsonParam.get("duration").toString();
        //根据设备序列号获取设备信息
        openService.controlMovePTZ(accessToken,deviceId,channelId,operation, duration);

        //返回结果
        return resultMap;
    }

}


